<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
   <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
   <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
   <script type="text/javascript">
	$(document).ready(function(){
		var checkDupliId=false;
		var checkDupliEmail=false;
		
		$("input[name=check]").click(function(){ 
			//<input type="button" name="check" value="중복체크" onclick="idCheck()">
			var id=$("input[name=id]").val(); 
			// <input type="text" name="id">
			$.ajax({
				type:"POST",
				url:"isExistId.inven", //url 을 노출시키지 않는다.
				data:"id="+id, //data:"id="+id
				dataType:"json", 
				success:function(jsonData){
					//alert( jsonData);
					if(jsonData==1){
						$("#checkId").html("<font color='red'>중복된 아이디입니다!</font>");
						// <span id="checkId"></span>
					}else{
						if($("#id").val()==""){
							$("#checkId").html("<font color='red'>아이디를 입력해주세요!</font>");
							return false;
						}
						$("#checkId").html("<font color='red'>사용가능한 아이디입니다.</font>");
						checkDupliId=true;
					}
				}
			}); //ajax
		});//click
					
					$("input[name=checkEmail]").click(function(){ 
						//<input type="button" name="check" value="중복체크" onclick="idCheck()">
						var email=$("input[name=email]").val(); 
						// <input type="text" name="email">
						$.ajax({
							type:"POST",
							url:"isExistEmailReg.inven", //url 을 노출시키지 않는다.
							data:"email="+email, //data:"email="+email
							dataType:"json", 
							success:function(jsonData){
								//alert( jsonData);
								if(jsonData!=0){
									$("#checkEmail").html("<font color='red'>중복된 이메일 입니다!</font>");
									// <span id="checkEmail"></span>
								}else{
									if($("#email").val()==""){
										$("#checkEmail").html("<font color='red'>이메일을 입력해주세요!</font>");
										return false;
									}
									$("#checkEmail").html("<font color='red'>사용가능한 이메일입니다.</font>");
									checkDupliEmail=true;
								}
							}
						}); //ajax
					});//click
		$("#registerForm").submit(function(){
			if(checkDupliId==false){
				alert("아이디 중복 체크를 하세요");
				return false;
			}
			if(checkDupliEmail==false){
				alert("이메일 중복 체크를 하세요");
				return false;
			}
			if($("#id").val()==""){
				alert("아이디를 입력해주세요");
				return false;
			}else if($("#password").val()==""){
				alert("비밀번호를 입력해주세요");
				$("#password").focus();
				return false;
			}else if($("#name").val()==""){
					alert("이름을 입력해주세요");
					return false;
			}else if($("#phone").val()==""){
						alert("전화번호를 입력해주세요");
						return false;
			}else if($("#email").val()==""){
							alert("이메일을 입력해주세요");
							return false;
			}
			if($("#id").val().length>=9){
				alert("아이디는 8자 이하로 작성해주세요");
				return false;
			}
		}); //공란체크
		
	 }); //document


</script>
<h3 align="center">회원 가입</h3>
<br>
<form id="registerForm" name="registerForm"  enctype="multipart/form-data"  action="registerInven.inven" method="post"
			onsubmit="return checkForm()">
	<table style="margin: auto;">
		<tr>
			<td style="width: 20%;">ID</td>
			<td colspan="2"><input style="width: 500px; height: 40px;" type="text" name="id" id="id" placeholder="아이디는 8자 이하로 작성해주세요"></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td><input class="login_button" type="button" name="check" value="중복체크" onclick="idCheck()"></td>
			<td><span id="checkId"></span></td>
		</tr>
		<tr>
			<td>PASSWORD</td>
			<td colspan="2"><input style="width: 500px; height: 40px;" type="password" name="password" id="password"></td>
		</tr>
		<tr>
			<td>NAME</td>
			<td colspan="2"><input style="width: 500px; height: 40px;" type="text" name="name" id="name"></td>
		</tr>
		<tr>
			<td>PHONE</td>
			<td colspan="2"><input style="width: 500px; height: 40px;" type="text" name="phone" id="phone"></td>
		</tr>
		<tr>
			<td>EMAIL</td>
			<td colspan="2"><input style="width: 500px; height: 40px;" type="text" name="email" id="email"></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td><input class="login_button" type="button" name="checkEmail" value="중복체크" onclick="checkEmail()"></td>
			<td><span id="checkEmail"></span></td>
		</tr>
		<tr>
			<td>PROFILE</td>
			<td colspan="2"><input style="width: 500px; height: 40px;" type="text" name="profile" id="profile"></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td colspan="2"><input type="file" name="uploadFile" id="uploadFile"></td>
		</tr>
		<tr>
			<td style="width: 20%;">&nbsp;</td>
			<td><input class="login_button" type="submit" value="회원가입"></td>
			<td>&nbsp;</td>
		</tr>		              
	</table>
		</form>